<template>
	<view class="index" v-if="form.id">
		<view class="customer-wrapper">
			<view class="customer-info">
				<view class="item">
					客户名称：{{ form.customerPetName || '' }} {{ form.mobilePhone || '' }}
				</view>
				<view class="item">
					下单日期：{{ form.orderDate }}
				</view>
			</view>
		</view>
		<view class="product-item" v-for="(item,index) in form.orderItems" :key="index" @click="goApply(item)">
			<view class="supplier-name">
				<view class="name">
					{{ item.supplierName }}
				</view>
				<view class="tel">
					{{ item.serviceTel || ''}}
				</view>
				<uni-icons type="right" color="#898989" size="18"></uni-icons>
			</view>
			<view class="info-wrapper">
				<image :src="item.productImage" mode="aspectFill" class="product-image"></image>
				<view class="info">
					<view class="title">
						{{ item.productName }}
					</view>
					<view class="number">
						货号：{{ item.productCode }}
					</view>
					<view class="spec-wrapper">
						<view class="spec">
							毛重{{ item.grossWeight }}斤 净重 {{ item.netWeight }}斤
						</view>
					</view>
				</view>
			</view>
			<view class="delivery-quantity">
				<view class="item">
					订货：{{ item.quantity }}件
				</view>
				<view class="item">
					实配：{{ item.actualQuantity }}件
				</view>
			</view>
			<view class="delivery-quantity afterSale" v-if="item.isAfterSales">
				<view class="item">
					已售后：{{ item.lossNum }}件
				</view>
				<view class="item">
					售后时间：{{ item.applyTime }}
				</view>
			</view>
		</view>
		<!-- <view class="btn-wrapper">
			<view class="btn default" @click="goback">
				取消
			</view>
			<view class="btn" @click="submit">
				确认自提
			</view>
		</view> -->

		<uni-popup ref="popup">
			<view class="popup-wrapper">
				<view class="title-wrapper">
					确认提货
				</view>
				<view class="form-item">
					<view class="label">
						提货码：
					</view>
					<view class="input-wrapper">
						<input type="digit" auto-focus v-model="code" placeholder="请输入提货码" class="input">
					</view>
				</view>
				<view class="popup-btn-wrapper">
					<view class="btn cancel" @click="confirm(0)">
						熟人,免码提货
					</view>
					<view class="btn" @click="confirm(1)">
						验码提货
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {},
				code: "",
				id: ''
			}
		},
		onLoad(option) {
			//console.log(option.id)
			this.id = option.id;
		},
		onShow() {
			this.getInfo(this.id)
		},
		computed: {

		},
		methods: {
			async getInfo(id) {
				const data = await this.$api.get('/app/deliver/order/getAfterSalesInfo', {
					id: id
				})
				data.data.orderItems.forEach(item => {
					item.productImage =
						"https://cdpresources.hobon.cc/supplier-mini-program/static/noProduct.png";
					if (item.mainImageVideo) {
						const mainImageVideo = JSON.parse(item.mainImageVideo)[0]
						if (mainImageVideo.type === 0) {
							item.productImage = mainImageVideo.url + '?imageView2/3/w/300/q/100'
						} else {
							item.productImage = mainImageVideo.url + '?vframe/jpg/offset/1'
						}
					}
				})
				this.form = data.data;
			},
			goApply(item) {
				const obj = {
					...item
				}
				if (item.isAfterSales && item.status !== 7 && item.status !== 8) {
					uni.showToast({
						title: '当前商品已经发起过售后，不能再次发起',
						icon: 'none',
						duration: 2000
					})
					return
				}
				obj.customerId = this.form.customerId;
				obj.customerPetName = this.form.customerPetName;
				obj.mobilePhone = this.form.mobilePhone;
				obj.orderDate = this.form.orderDate;
				uni.setStorageSync('afterSaleApplyProductInfo', obj)
				uni.navigateTo({
					url: '/subPage_afterSale/apply'
				})
			},
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: auto;
		padding-bottom: 150upx;

		.customer-wrapper {
			background-color: #F26022;
			display: flex;
			align-items: center;
			color: #ffffff;
			padding: 30upx;
			border-radius: 0 0 20upx 20upx;

			.customer-info {
				flex: 1;

				.item {
					&:first-child {
						margin-bottom: 10upx;
					}
				}
			}

			.storage-number {
				margin-left: 50upx;
				text-align: center;
				font-weight: bold;
				font-size: 38upx;
			}
		}

		.product-item {
			background-color: #ffffff;
			border-radius: 20upx;
			margin: 20upx 20upx 0 20upx;
			overflow: hidden;


			.supplier-name {
				padding: 20upx;
				display: flex;
				background-color: #F5F6FA;

				.name {
					flex: 1;
					font-weight: bold;
					font-size: 32upx;
					color: #212121;
				}
			}

			.info-wrapper {
				display: flex;
				padding: 20upx;

				.product-image {
					width: 140upx;
					height: 140upx;
					min-width: 140rpx;
					margin-right: 20upx;
					border-radius: 10upx;
				}

				.info {
					flex: 1;
					width: 500rpx;

					.title {
						font-size: 32upx;
						line-height: 36upx;
						margin-bottom: 20upx;
						width: 500rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden; //溢出内容隐藏
						text-overflow: ellipsis; //文本溢出部分用省略号表示
						display: -webkit-box; //特别显示模式
						-webkit-line-clamp: 1; //行数
						line-clamp: 1;
						-webkit-box-orient: vertical; //盒子中内容竖直排列
						font-weight: bold;
						color: #343434;
					}

					.number {
						font-size: 28upx;
						color: #555555;
						line-height: 28upx;
						margin-bottom: 20upx;
					}

					.spec-wrapper {
						display: flex;
						align-items: center;

						.price {
							font-size: 34upx;
							font-weight: bold;
							color: #FC003B;
							margin-right: 20upx;
						}

						.spec {
							font-size: 28upx;
							color: #555;
						}
					}
				}
			}

			.delivery-quantity {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 20upx;
				border-top: 1upx solid #efefef;
				color: #666666;

				.item {
					font-size: 30upx;

				}

				&.afterSale {
					color: #F26022;
					border-top: 0;
					padding-top: 0;
					margin-top: -10upx;
				}
			}
		}

		.btn-wrapper {
			position: fixed;
			height: 100upx;
			width: 100%;
			bottom: 0;
			background-color: #ffffff;
			display: flex;
			align-items: center;
			z-index: 9;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				height: 100%;
				background-color: #F26022;
				color: #ffffff;

				&.default {
					color: #232323;
					background-color: #ffffff;
				}
			}
		}

		.popup-wrapper {
			width: 600upx;
			background-color: #ffffff;
			border-radius: 20upx;
			min-height: 300upx;
			overflow: hidden;

			.title-wrapper {
				height: 100upx;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 32upx;
				font-size: 36upx;
				color: #2B2B2B;
			}

			.form-item {
				margin: 0 44upx;
				height: 100upx;
				display: flex;
				align-items: center;
				border-bottom: 2upx solid #f9f9f9;

				.label {
					font-size: 32upx;
					color: #5B5B5B;
				}

				.input-wrapper {
					height: 70upx;
					flex: 1;
					border: 1upx solid #dedede;
					border-radius: 10upx;
					margin-right: 15upx;

					.input {
						height: 70upx;
						width: 100%;
						text-align: center;
					}
				}
			}

			.popup-btn-wrapper {
				height: 150upx;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 40upx;

				.btn {
					width: 260upx;
					height: 76upx;
					border-radius: 40upx;
					background-color: #F26022;
					color: #ffffff;
					display: flex;
					align-items: center;
					justify-content: center;
					transition: .15s linear;

					&:active {
						background-color: #F2602266;
					}

					&.cancel {
						box-sizing: border-box;
						background-color: #ffffff;
						border: 2upx solid #F26022;
						margin-right: 40upx;
						color: #F26022;

						&:active {
							background-color: #F2F4FA77;
						}
					}
				}
			}
		}
	}
</style>